import http from "../../utils/http"
Page({
  data: {
    active: 0,
    imageURL: "/images/banner/banner1.png",
    value: "",
    search: {
      page: 1,
      size: 10,
      title: "",
      type: "vue",
    },
    dataList: []
  },
  onLoad() {
    this.getDataList()
  },
  // 切换 Tab
  changeTab(event) {
    this.setData({
      'search.type': event.detail.title
    });
    this.getDataList();
  },
  // 搜索博客
  searchBlog(event) {
    this.setData({
      'search.title': event.detail.value
    });
    this.getDataList();
  },
  // 获取列表数据
  async getDataList() {
    const res = await http.get("/blog/page", this.data.search);
    this.setData({
      dataList: res.data.records
    })
  },
  // 进入博客详情页
  enterBlogDetail(event) {
    // 进入博客详情页，传递参数
    wx.redirectTo({
      url: '/pages/blog/detail/index?id=' + event.target.id,
    })
  },
  // 进入新增博客页面
  enterAddUpdate() {
    wx.redirectTo({
      url: '/pages/blog/addUpdate/index',
    })
  }
})